package strain.domain;

import java.util.Comparator;

public class CompareWrapper<T> implements Comparator<T> {
    
    public static <T1 extends Comparable<T2>, T2> boolean equal(final T1 t1, final T2 t2){
        return (t1.compareTo(t2) == 0);
    }
    
    public static <T1 extends Comparable<T2>, T2> boolean less(final T1 t1, final T2 t2){
        return (t1.compareTo(t2) < 0);
    }
    
    public static <T1 extends Comparable<T2>, T2> boolean greater(final T1 t1, final T2 t2){
        return (t1.compareTo(t2) > 0);
    }
    
    public static <T1 extends Comparable<T2>, T2> boolean lessOrEqual(final T1 t1, final T2 t2){
        return !greater(t1, t2);
    }
    
    public static <T1 extends Comparable<T2>, T2> boolean greaterOrEqual(final T1 t1, final T2 t2){
        return !less(t1, t2);
    }
    
    public static <T extends Comparable<T>> T min(final T t1, final T t2){
        if (t1.compareTo(t2) <= 0){
            return t1;
        }
        return t2;
    }
    
    public static <T extends Comparable<T>> T max(final T t1, final T t2){
        if (t1.compareTo(t2) >= 0){
            return t1;
        }
        return t2;
    }

    private final Comparator<? super T> comparator;
    
    public CompareWrapper(final Comparator<? super T> comparator){
        this.comparator = comparator;
    }
    
    public int compare(final T t1, final T t2) {
        return this.comparator.compare(t1, t2);
    }
    
    public boolean equal(final T t1, final T t2){
        return (compare(t1, t2) == 0);
    }
    
    public boolean less(final T t1, final T t2){
        return (compare(t1, t2) < 0);
    }
    
    public boolean greater(final T t1, final T t2){
        return (compare(t1, t2) > 0);
    }
    
    public boolean lessOrEqual(final T t1, final T t2){
        return !greater(t1, t2);
    }
    
    public boolean greaterOrEqual(final T t1, final T t2){
        return !less(t1, t2);
    }
    
    public T min(final T t1, final T t2){
        if (compare(t1, t2) <= 0){
            return t1;
        }
        return t2;
    }
    
    public T max(final T t1, final T t2){
        if (compare(t1, t2) >= 0){
            return t1;
        }
        return t2;
    }
    
}
